package de.fh.ka.as.car.util;

public class RangeConverter {
	private double inputMin;
	private double inputMax;

	private double outputMin;
	private double outputMax;

	public RangeConverter(double inputMin, double inputMax, double outputMin, double outputMax) {
		this.inputMin = inputMin;
		this.inputMax = inputMax;
		this.outputMin = outputMin;
		this.outputMax = outputMax;
	}

	public double toOutput(double input) {
		// if (input < inputMin || inputMax < input) {
		// throw new
		// IllegalArgumentException(String.format("Input was %s but must be between %s and %s",
		// input, inputMin, inputMax));
		// }
		return (((input - inputMin) / getInputRange()) * getOutputRange()) + outputMin;
	}

	public double toInput(double output) {
		// if (output < outputMin || outputMax < output) {
		// throw new
		// IllegalArgumentException(String.format("Output was %s but must be between %s and %s",
		// output, outputMin, outputMax));
		// }
		return (((output - outputMin) / getOutputRange()) * getInputRange()) + inputMin;
	}

	public double getInputRange() {
		return inputMax - inputMin;

	}

	public double getOutputRange() {
		return outputMax - outputMin;
	}

	public double getInputMin() {
		return inputMin;
	}

	public void setInputMin(double inputMin) {
		this.inputMin = inputMin;
	}

	public double getInputMax() {
		return inputMax;
	}

	public void setInputMax(double inputMax) {
		this.inputMax = inputMax;
	}

	public double getOutputMin() {
		return outputMin;
	}

	public void setOutputMin(double outputMin) {
		this.outputMin = outputMin;
	}

	public double getOutputMax() {
		return outputMax;
	}

	public void setOutputMax(double outputMax) {
		this.outputMax = outputMax;
	}

}
